export default{
    data(){
        return{
            modal1:false,//对话框
            ids:[],
            list:[],
            filter:{
                page:1,
                rows:5,
                name:'',
                total:0,
                pages:1,
            }
        }
    },
    methods:{
        onPageSizeChange(pageSize){
            this.filter.rows=pageSize;
            this.getData();
        },
        changePage(page){
            this.filter.page=page;
            this.getData();
        },
        //增加
        addData(){
            this.modal1=true;
        },
        //删除一个或多个
        removeData(selection){
            console.log(selection)               
            if(Array.isArray(selection)){
                var arr=[];
                selection.forEach(function(obj) {
                    arr.push(obj._id)
                }, this);
                selection=arr
            }   
            this.$http({
                method:'DELETE',
                url:`http://localhost:3000/${this.module}/data/`+selection
            }).then((response)=>{
                this.getData();
            })
            
        },
        //修改数据
        editData(id){
            this.$http({
                method:'GET',
                url:`http://localhost:3000/${this.module}/data/`+id,   //重新增加了 ：添加单个数据的node后台
            }).then((response)=>{                             //user.controller和users
            //    console.log(1)
                // console.log(response.data)
                this.formValidate=response.data;
            })

            this.modal1=true;
            this.getData();
        },
        //查找数据
        getData(){
            //console.log(this.module);
            this.$http({
                method:'POST',
                url:`http://localhost:3000/${this.module}/list`,
                data:this.filter
            })
            .then(res=>{
                // console.log(res.data);
                this.list=res.data.rows;
                this.filter.total=res.data.pages;
                //console.log(this.list)
            })
        },
        search(){
            this.getData();
        }
    },
    created(){
        this.getData();
    }
}




/* import 和 mixins */